package com.huzz.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.huzz.util.JackAuthorityDeserializer;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 描述
 *
 * @author Huzz
 * @create 2022-08-18 11:54
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
public class SysUser implements UserDetails {

    private Integer id;
    private String username;
    private String password;
    private Integer status = 0;
    @JsonDeserialize(using = JackAuthorityDeserializer.class)
    private Collection<? extends GrantedAuthority> authorities;

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return status != 1;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return status != 2;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return status != 3;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return status != 4;
    }
}
